package com.rickpan.controller;

import com.rickpan.annotation.VipFeature;
import com.rickpan.common.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * VIP功能使用示例控制器
 * 展示如何在业务接口中集成VIP功能限制
 */
@RestController
@RequestMapping("/api/example")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "VIP功能示例", description = "展示VIP功能限制的使用方法")
public class VipFeatureExampleController {

    /**
     * AI工作报告生成示例
     */
    @PostMapping("/ai-report/generate")
    @VipFeature(value = "AI_REPORT", description = "AI工作报告生成")
    @Operation(summary = "生成AI工作报告", description = "使用AI生成工作报告 (BASIC用户每月限制50次)")
    public ApiResponse<Map<String, Object>> generateAIReport(@RequestBody Map<String, Object> reportData) {
        // 模拟AI报告生成逻辑
        Map<String, Object> result = new HashMap<>();
        result.put("reportId", System.currentTimeMillis());
        result.put("title", "AI生成的工作报告");
        result.put("content", "这是一个由AI生成的工作报告内容...");
        result.put("generatedAt", System.currentTimeMillis());
        
        log.info("成功生成AI工作报告");
        return ApiResponse.success(result);
    }

    /**
     * 团队创建示例
     */
    @PostMapping("/team/create")
    @VipFeature(value = "TEAM_CREATE", description = "团队创建")
    @Operation(summary = "创建团队", description = "创建新团队 (BASIC用户总计限制3个)")
    public ApiResponse<Map<String, Object>> createTeam(@RequestBody Map<String, Object> teamData) {
        // 模拟团队创建逻辑
        Map<String, Object> result = new HashMap<>();
        result.put("teamId", System.currentTimeMillis());
        result.put("teamName", teamData.get("teamName"));
        result.put("createdAt", System.currentTimeMillis());
        
        log.info("成功创建团队: {}", teamData.get("teamName"));
        return ApiResponse.success(result);
    }

    /**
     * 高级文件分享示例
     */
    @PostMapping("/share/advanced")
    @VipFeature(value = "FILE_SHARE_ADVANCED", description = "高级文件分享")
    @Operation(summary = "高级文件分享", description = "创建高级文件分享 (BASIC用户每月限制10次)")
    public ApiResponse<Map<String, Object>> createAdvancedShare(@RequestBody Map<String, Object> shareData) {
        // 模拟高级分享创建逻辑
        Map<String, Object> result = new HashMap<>();
        result.put("shareId", System.currentTimeMillis());
        result.put("shareUrl", "https://rickpan.com/s/" + System.currentTimeMillis());
        result.put("expireTime", System.currentTimeMillis() + 7 * 24 * 60 * 60 * 1000); // 7天后过期
        result.put("password", "abc123");
        result.put("downloadLimit", shareData.get("downloadLimit"));
        
        log.info("成功创建高级文件分享");
        return ApiResponse.success(result);
    }

    /**
     * 不需要VIP限制的普通功能示例
     */
    @GetMapping("/public/info")
    @Operation(summary = "获取公共信息", description = "不需要VIP权限的公共功能")
    public ApiResponse<Map<String, Object>> getPublicInfo() {
        Map<String, Object> info = new HashMap<>();
        info.put("appName", "RickPan");
        info.put("version", "5.0");
        info.put("description", "企业级智能工作平台");
        
        return ApiResponse.success(info);
    }
}